function confirmUpload(fileName, fileType) {
	//如果用户确认要上传这个附件，就把附件的链接贴到用户的输入框中
	var filePath;
	if (fileType == "picture")
		filePath = '<img src="../' + fileName + '">';
	else
		filePath = '<a href="../' + fileName + '">' + fileName + '</a>';
	addAttachLinkToTextarea(filePath);
}

function addAttachLinkToTextarea(str) {
	//将str添加到特定的textarea中
	var commentContentTextArea = $("#commentContentTextArea");
	var articleContentTextArea = $("#articleContentTextArea");
	var ubb;
	if (commentContentTextArea.length > 0) {
		ubb = commentContentTextArea[0];
	} else if (articleContentTextArea.length > 0) {
		ubb = articleContentTextArea[0];
	}

	var ubbLength = ubb.value.length;

	ubb.focus();
	if (typeof document.selection != "undefined") {
		document.selection.createRange().text = str;
	} else {
		ubb.value = ubb.value.substr(0, ubb.selectionStart) + "\n" + str + "\n"
				+ ubb.value.substring(ubb.selectionStart, ubbLength);
	}
}

function uploadFile() {
	//用户确认上传文件之后，要做的事情
	//1.将输入框清空
	setTimeout("clearFilePath()", 1000);
}

function clearFilePath() {
	$("#filePath")[0].value = "";
}

function addAttachmentToDiv(fileName, fileType) {
	//这个函数的作用是在attachment块中添加用户上传的附件的链接，由动态刷新的iframe调用

	var linkBlock = '<a href="' + fileName + '"' + '>' + fileName + '</a>';
	var buttonBlock;
	var newLine = '<br>';
	var divArticleArea = $("#articleArea");
	var divAttachmentArea = $("#attachment_area");
	if (fileType == "picture") {
		buttonBlock = '<button type="button" onclick="confirmUpload(' + "'"
				+ fileName + "'" + "," + "'" + fileType + "'"
				+ ')">插入图片</button>';
	} else {
		buttonBlock = '<button type="button" onclick="confirmUpload(' + "'"
				+ fileName + "'" + "," + "'" + fileType + "'"
				+ ')">插入附件链接</button>';
	}

	divAttachmentArea.after(linkBlock + buttonBlock + newLine);

};
